package com.nogroup.springbootproject.service.impl;

import com.nogroup.springbootproject.dto.CclassDto;
import com.nogroup.springbootproject.dto.ExamDto;
import com.nogroup.springbootproject.entity.Cclass;
import com.nogroup.springbootproject.dao.CclassDao;
import com.nogroup.springbootproject.entity.Exam;
import com.nogroup.springbootproject.service.CclassService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Cclass)表服务实现类
 *
 * @author makejava
 * @since 2024-04-07 19:03:50
 */
@Service("cclassService")
@Transactional(rollbackFor = Exception.class)
public class CclassServiceImpl implements CclassService {
    @Resource
    private CclassDao cclassDao;

    /**
     * 通过ID查询单条数据
     *
     * @param classCode 主键
     * @return 实例对象
     */
    @Override
    public Cclass queryById(String classCode) {
        return this.cclassDao.queryById(classCode);
    }

    /**
     * 分页查询
     *
     * @param cclass 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Cclass> queryByPage(Cclass cclass, PageRequest pageRequest) {
        long total = this.cclassDao.count(cclass);
        return new PageImpl<>(this.cclassDao.queryAllByLimit(cclass, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param cclass 实例对象
     * @return 实例对象
     */
    @Override
    public Cclass insert(Cclass cclass) {
        this.cclassDao.insert(cclass);
        return cclass;
    }

    /**
     * 修改数据
     *
     * @param cclass 实例对象
     * @return 实例对象
     */
    @Override
    public Cclass update(Cclass cclass) {
        this.cclassDao.update(cclass);
        return this.queryById(cclass.getClassCode());
    }

    /**
     * 通过主键删除数据
     *
     * @param cclass 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Cclass cclass) {
        return this.cclassDao.deleteById(cclass) > 0;
    }

    @Override
    public List<Cclass> getAllClasses() {
        return cclassDao.getAllClasses();
    }

    @Override
    public List<Cclass> getClassesByFuzzySearch(CclassDto cclassDto) {
        return cclassDao.getClassesByFuzzySearch(cclassDto);
    }

    @Override
    public Long countPage(CclassDto cclassDto) {
        return cclassDao.CountPage(cclassDto);
    }
}
